

#ifndef EM_ECG_H__
#define EM_ECG_H__

#include <stdint.h>
#include <stdbool.h>


//#define EMECG_DATA_TYPE_NONE                 0
//#define EMECG_DATA_TYPE_ecg                  1
//#define EMECG_DATA_TYPE_BP                   2
//#define EMECG_DATA_TYPE_SPO2                 3
//#define EMECG_DATA_TYPE_DET                  4

typedef enum
{
    EM_ECG_EVT_TYPE_INVALID = 0,
    EM_ECG_EVT_TYPE_INT,
    EM_ECG_EVT_TYPE_TIMEOUT,
    EM_ECG_EVT_TYPE_ECG_RESULT,
    EM_ECG_EVT_TYPE_BP_RESULT,
    EM_ECG_EVT_TYPE_SPO2_RESULT,
    EM_ECG_EVT_TYPE_DETECT_RESULT,
    EM_ECG_EVT_TYPE_CROSSTALK,
}em_ecg_evt_type_t; 

typedef enum 
{
    EMECG_WORK_MODE_STOP = 0,
    EMECG_WORK_MODE_ECG,
    EMECG_WORK_MODE_BLOODPRESSURE,
    EMECG_WORK_MODE_SPO2,
    EMECG_WORK_MODE_DETECT, 
}em_ecg_work_mode_t;

typedef enum{
    EM_EC_EVT_TYPE_NOT_OPEN,
    EM_EC_EVT_TYPE_NO_TOUCH,
    EM_EC_EVT_TYPE_READY,
    EM_EC_EVT_TYPE_TIMEOUT,    
}em_ecg_code_t;

typedef struct{
    em_ecg_code_t   type;
    uint8_t         ECG;
}em_ecg_result_t; 

typedef struct 
{
    em_ecg_evt_type_t type;
    
    union
    {
        em_ecg_result_t ECG;
    }param;
    
}em_ecg_evt_t;

typedef struct
{
    uint8_t gender;
    uint8_t age;
    uint8_t weight;
    uint8_t height;
    uint8_t skin;
}em_ecg_init_t;

typedef struct
{
    uint16_t chip_id;
}em_ecg_desc_t;


typedef void (*em_ecg_evt_handle_t)(em_ecg_evt_t const * p_evt );

////////////////////////////////////////////////////////////////


void em_ecg_init(void);


// if has dynamic ecg, these function below use to fill acc data 
void em_ecg_acc_data_reset(void);

void em_ecg_acc_data(int16_t* data, uint32_t count);

void em_ecg_add_acc_static_data(int16_t* data);

int em_ecg_acc_data_find_by_length( uint16_t ppgCnt );




typedef struct{
    void (*setup)(em_ecg_init_t* p_init_obj);
    bool (*mounting)(em_ecg_desc_t* pdesc);
    void (*start)(uint32_t mode);
    void (*stop)(void);
    // void (*set_work_mode)(uint32_t mode);
    
    void (*register_callback)( em_ecg_evt_handle_t cb );
    
    void (*timeout)(void);
    void (*process)(void);
}em_ecg_instance_t;


void em_ecg_init_dlps(void);

void em_ecg_enter_dlps(void);

void em_ecg_exit_dlps(void);

bool em_ecg_wakeup_check_allow_dlps(void); 

void em_ecg_register_callback(em_ecg_evt_handle_t cb);

const em_ecg_instance_t* em_ecg_list_mouting( em_ecg_desc_t* p_desc );


#endif 
